#include <iostream>
#include <string>
using namespace std;




int main(){
	string s;
	int n,m;
	cin>>n>>m;
	cin>>s;
	unsigned char ss[n];
	for(int i=0;i<n;i++){
		ss[i] = s[i] - '0';
	}
	for(int i=0;i<m;i++){
		int op,l,r;
		cin>>op>>l>>r;
		int j = l-1;
		if(!op){
			while(j+1 != r){
				ss[j] = 1-ss[j];
				j++;
				j = j%n;
			}
			ss[r-1] = 1-ss[r-1];
		}
		else{
			int num = 0;
			while(j+1 != r){
				num += ss[j];
				j++;
				j = j%n;
			}
			num += ss[r-1];
			cout<<num<<endl;
		}
	}
} 
